install.packages("ggplot2")
#####pdf文件
pdf("1.pdf",width = 4,height = 4)
x<-c(1,2,3,4)
y<-c(3,4,5,6)
plot(x,y,type="o",pch=1:25)
dev.off()#关闭制图
graphics.off()
#####直方图
cs<-"D://文件//1//汇总.csv"
data1<-read.csv(cs)
data1<-data1[,-2]
data2<-as.matrix(data1)
data3<-unlist(data2)##两种二维转一维
data3<-log2(data3)
hist(data2,col="red",labels = TRUE)
pdf("2.pdf",width = 4,height = 4)
hist(data3)
dev.off()
#####层次聚类
data4<-data1[,-1]
data5<-as.matrix(data4)#转为一维
distance<-dist(data5)#计算欧氏距离
tree<-hclust(distance)
plot(tree)
#######火山图
library(ggplot2)
setwd("D:\\文件\\1")
load("volcano.RData")
P1=0.05
prostat$change <- NA
for (i in 1:nrow(prostat))
{
  if(prostat$P[i]<0.05)
  {
    if(prostat$FC[i]>log2(1.2))
      {prostat$change[i]<-'up'}
    else if(prostat$FC[i]<log2(1.2))
      {prostat$change[i]<-'down'}
  }
  else if(prostat$P[i]>0.05)
    prostat$change[i]<-'stable'
}#分类UP，down,stable
fire<-ggplot(data=prostat,mapping=aes(x=FC,y=-log10(P),colour=factor(change)))+geom_point(aes())+scale_color_manual(values=c("green", "black", "red")) 
#设置映射颜色
plot(fire)
jpeg("fire.jpg", width = 800, height = 600, quality = 100)
print(fire)
dev.off()##保存为jpg格式


                        
